<?php
class Contact extends MY_Controller {

	function Contact()

	{
		parent::MY_Controller();
		$this->load->model('Contact_model');
	}
	function index()
	{	
		// Set meta
		$title = $this->data['site']['site_title'];
		$data['web_title'] = "SipDev | Contac Us";
		$data['meta_title'] = $title;
		$data['meta_description'] = purify($this->data['site']['site_description']);
		$data['meta_keyword'] = $this->data['site']['site_keyword'];

		// Send and Load page
		$data['page'] = 'contact_view';
		$this->load->vars($data);
		$this->load->view('template_view');	

	}

	

	function doSend()

	{

		$rules =array(

					array(

							'field'=>'name',

							'label'=>'Name',

							'rules'=>'trim|required|xss_clean|max_length[255]'

					),

					array(

							'field'=>'phone',

							'label'=>'Phone',

							'rules'=>'trim|xss_clean|max_length[50]'

					),

					array(

							'field'=>'email',

							'label'=>'Email',

							'rules'=>'trim|required|xss_clean|valid_email|max_length[255]'

					),

					

					array(

							'field'=>'message',

							'label'=>'Message',

							'rules'=>'trim|required|xss_clean'

					)	

			);	

		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');		

		$this->form_validation->set_rules($rules);	

		

		if ($this->form_validation->run()==FALSE)

		{

				$this->session->set_flashdata('contact', '<div class="result_error"><h3>Send Message Failed!</h3></div>'); 

		}

		else

		{

			$status = 'I';

			$ip=$this->input->ip_address();

			$this->Contact_model->insert($status);

			// Send Email

			$this->email->clear();

			$this->email->from('no-reply@sipdev.net', 'Pesan Dari Website');

			$this->email->to('info@sipdev.net, noviri.firmansyah@sipdev.net, riki.bahtiar@sipdev.net, ari.sofyan@sipdev.net', 'info.sipdev@gmail.com');		

			$this->email->subject('[sipdev.net]: Anda mendapat pesan ');	// Edit Judul			

			$message = 'Assalammua`laikum wr. wb.: <br /><br /> ';

			$message .= 'Anda mendapatkan pesan dari : <br /> ';

			$message .= '<b>Nama:</b><br> ' . $this->input->post('name') . '<br />';

			$message .= '<b>Alamat:</b><br> ' . $this->input->post('address') . '<br />';

			$message .= '<b>Email:</b><br> <a href="mailto:'.$this->input->post('email').'">' . $this->input->post('email') . '</a><br />';

			$message .= '<b>Telp:</b><br> ' . $this->input->post('phone') . '<br />';

			$message .= '<b>Pesan:</b><br> ' . $this->input->post('message') . '<br />';

			$message .= '<b>Tanggal dikirim:</b><br>' . date("Y-m-d H:i:s") . '<br />';

			$message .= '<b>IP Address:</b><br>' . $this->input->ip_address() . '<br />';			

			$message .= '<br /><br />Terima Kasih,<br /> sipdev.net team';	

									

			$this->email->message($message);

			$this->email->send();

			$this->email->print_debugger();

			$this->session->set_flashdata('contact', '<div class="result_success"><h3>Thanks! We will reply as soon as possible</h3></div>');				

			redirect("contact-us");

			

		}

		// Set meta

		$title = $this->data['site']['site_title'];

		$data['web_title'] = $title;

		$data['meta_title'] = $title;

		$data['meta_description'] = purify($this->data['site']['site_description']);

		$data['meta_keyword'] = $this->data['site']['site_keyword'];

		

		$data['page'] = 'contact_view';

		$this->load->vars($data);

		$this->load->view('template_view');

	}

	

}	



/* End of file contact.php */

/* Location: ./application/controllers/Contact.php */

?>